using UnityEngine;
using System.Collections;

public class Spawner : MonoBehaviour {
	
	
	public GameObject enemy;
	
	ArrayList enemy_List;
	bool addEnemy;
	public int max_Enemy_Count;
	private int enemy_Count;
	private Vector3 createPosition;
	

	// Use this for initialization
	void Start () {
		
		enemy_List = new ArrayList();
		//all_enemies = new ArrayList<GameObject>();
	}
	
	// Update is called once per frame
	void Update () {
//GameObject.Find();
		createPosition = transform.position;
	
	}
	
	void Spawn(){
		
	}
	
	public void SetSpawn(){
		 GameObject[] gos;
        gos = GameObject.FindGameObjectsWithTag("TieFighter");
        GameObject closest;
        float distance = Mathf.Infinity;
        Vector3 position = transform.position;
        foreach (GameObject go in gos) {
            Vector3 diff = go.transform.position - position;
            float curDistance = diff.sqrMagnitude;
            if (curDistance < distance) {
                closest = go;
                distance = curDistance;
				createPosition = transform.position-closest.transform.position;
            }
        }
		
		enemy_List.Add(GameObject.Instantiate(enemy,createPosition, Quaternion.identity));
		
		
		
	}
}
